'''
Created on 2014-04-10

@author: masinko
'''
import re
import urllib2

def fileReader(src,starttext,endtext,length):
    data = []
    start = 0
    end = 0
    length = 105
    with open (src, "r",encoding="utf8") as myfile:
        for i, line in enumerate(myfile, 1):
            if starttext in line:
                start = i
                if length != 0:
                    end = start + length
                else:
                    if endtext in line:
                        end = i
            if start > 0 and i >= start and i < end and end > 0  : 
                data.append(line)
    return ' '.join(data)

def urlReader(url):
    req = urllib2.Request(url)
    req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0')
    response = urllib2.urlopen(req)
    urlsource = response.read().decode("ISO-8859-1")
    response.close()
    return urlsource

def extractSubString(string,startstr,endstr,start=0):
    startindex = string.find(startstr,start)
    endindex = string.find(endstr,startindex)
    substring = string[startindex:endindex]
    return substring

def find(regEx,src):
    return re.compile(regEx).findall(src)

def removeNonASCII(text):
    return ''.join([i if ord(i) < 128 else ' ' for i in text])
        

if __name__ == '__main__':
    pass